package org.example;

import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebServlet;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/mygeneric")
//继承Generic来实现 localhost:9527/myGeneric?username=小明
public class MyGeneric extends GenericServlet {
    @Override
    public void service(ServletRequest servletRequest, ServletResponse servletResponse) throws ServletException, IOException {
        String uname = servletRequest.getParameter("username");
        System.out.println("获取用户名"+uname);
        //设置响应及格式编码
        servletResponse.setContentType("text/html;charset=UTF-8");
        PrintWriter out = servletResponse.getWriter();
        out.write("收到哦"+uname);
        out.flush();
        out.close();
    }
}
